/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Response;

import java.io.*;
import java.util.*;
import AccManager.UserProfile;
import Request.RequestType;
import Request.*;
import AccManager.*;

/**
 *
 * @author lcy
 */
public class NetDataUserListResp extends NetDataResponse implements Serializable{

    List<UserProfile> _user_list;

    public NetDataUserListResp(){
        super();
        InitCommComponents();
    }

    
    public NetDataUserListResp(List<UserProfile> user_list){
        super();
        _user_list = user_list;
        InitCommComponents();
    }

    private void InitCommComponents(){
        _resp_type = RespType.USERLIST;
    }

    public Object GetResponseContent(){

        return _user_list;
    }

    
    public void CopyList(List<UserProfile> list) throws NullPointerException{

        if(_user_list == null || list == null){
            throw new NullPointerException("Copy list is null");
        }

        for(int idx = 0; idx < list.size();idx ++){
            UserProfile new_user = new UserProfile(list.get(idx));
            _user_list.add(new_user);
        }
    }

    //Pre: @list: list is not null
    public void CreateReturnList(UserProfile requestProfile,List<UserProfile> list)
    throws NullPointerException{

        if(_user_list == null || list == null){
            throw new NullPointerException("Copy list is null");
        }

        for(int i = 0; i < list.size(); i++){

            UserProfile nextUser = list.get(i);
            UserStatus status = nextUser.GetUserStatus();

            //All online users are to be added
            //All contacts are to be added
            if( status == UserStatus.ONLINE || status == UserStatus.INGAME){
                UserProfile addedProfile = new UserProfile(nextUser);
                addedProfile.SetPasswd("******");
                _user_list.add(addedProfile);
            }
            else{
                if(requestProfile.FindContact(nextUser.GetUserID()) != null){
                    UserProfile addedProfile = new UserProfile(nextUser);
                    addedProfile.SetPasswd("******");
                    _user_list.add(addedProfile);
                }
            }
        }
    }

    public void SetRequest(Request request){
        _request = new UserListRequest((UserListRequest)request);
    }

}
